<template>
	<view style="background-color: #fff;height: 100%;">
		<image src="../../static/009.jpg" style="width: 750rpx; height: 100%; position: absolute;"></image>
			
		<view class="uni-common-mt" style="padding: 20px; padding-top: 90%; position: relative;">
			<view class="uni-form-item uni-column">
				<input
					style="padding: 5px 0 5px 15px;border: 1px solid #808080; border-radius: 8px; margin-bottom: 12px;"
					class="uni-input" v-model="account" focus placeholder="账号" />
			</view>
			<view class="uni-form-item uni-column">
				<input type="password" style="padding: 5px 0 5px 15px;border: 1px solid #808080; border-radius: 8px;"
					class="uni-input" v-model="password" focus placeholder="密码" />
			</view>
			<view class="uni-form-item uni-column" style="margin-top: 10px;">
				<checkbox-group @change="read">
					<label style="font-size: 14px;color: gray;">
						<checkbox style="transform:scale(0.7)" value="1" :checked=is_read />我已阅读<view
							style="display: inline-block;">《用户协议》</view>
					</label>
				</checkbox-group>
			</view>
			<button style="margin-top: 40px; background-color: red; border-radius: 10px;" type="primary"
				@click="login">立即登录</button><!-- 这种写法只有h5平台支持，不跨端，不推荐使用 -->
			<view style="text-align: right;margin-top: 10px;">
				<view class="txt" style="color: #000000;">忘记密码</view>
				<view @click="register()" class="txt" style="color: #000000;">注册账号</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				password: '',
				is_read: false,
				
			}
		},
		onLoad() {
			
		},
		methods: {
			read(e) {
				this.is_read = !this.is_read;
			},
			login() {
				if (!this.is_read) {
					uni.showToast({
						title: '请确定已阅读协议',
						duration: 2000,
						icon: 'none',
					})
					return;
				}
				if (this.account == '' || this.password == '') {
					return;
				}
				this.$api.postSignin({
						account: this.account,
						password: this.password
					})
					.then(res => {
						if (res.meta.code == '000') {
							uni.setStorageSync('uid', res.data.id);
							uni.setStorageSync('type', res.data.type);
							uni.setStorageSync('username', res.data.username);
							uni.setStorageSync('avatar', res.data.avatar);
							uni.setStorageSync('mobile_number', res.data.mobile_number);
							uni.setStorageSync('access_token', res.data.access_token);
							uni.setStorageSync('balance', res.data.balance);
							uni.setStorageSync('is_login', 1);
							uni.redirectTo({
								url: '/pages/index/index'
							});
						}
					}).catch(e => {

					})
			},
			register() {
				uni.navigateTo({
					url: '/pages/user/signup'
				})
			},
		}
	}
</script>

<style>
	.txt {
		display: inline-block;
		position: relative;
		font-size: 14px;
		padding: 0 20px;
		color: gray;
	}

	.txt:nth-child(2) {
		padding-right: 0;
	}

	.txt:nth-child(1)::after {
		content: "";
		width: 1px;
		height: 80%;
		position: absolute;
		top: 10%;
		right: 0;
		background: gray;
	}
</style>
